package com.fs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.mapper.UserInfoMapper;
import com.fs.pojo.UserInfo;
import com.fs.service.UserInfoService;
import com.fs.vo.PageBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Version:1.0
 * @Description: TODO(一句话描述该类的功能)
 * @Date: 2024/9/25 20:08
 * @Author: love you qxl
 */
@Service
public class UserInfoServiceImpl implements UserInfoService {
    @Resource
    private UserInfoMapper userInfoMapper;

    public void setUserInfoMapper(UserInfoMapper userInfoMapper) {
        this.userInfoMapper = userInfoMapper;
    }

    @Override
    public boolean add(UserInfo userInfo) {
        int insert = userInfoMapper.insert(userInfo);
        return insert>0 ? true:false;
    }

    @Override
    public boolean update(UserInfo userInfo) {
        LambdaUpdateWrapper<UserInfo> userInfoLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        userInfoLambdaUpdateWrapper.set(UserInfo::getName,userInfo.getName())
                .set(UserInfo::getGender,userInfo.getGender()).set(UserInfo::getAge,userInfo.getAge())
                .set(UserInfo::getEmail,userInfo.getEmail()).set(UserInfo::getQq,userInfo.getQq())
                .set(UserInfo::getAddress,userInfo.getAddress()).eq(UserInfo::getId,userInfo.getId());
        int update = userInfoMapper.update(userInfoLambdaUpdateWrapper);
        return update>0 ? true : false;
    }

    @Override
    public UserInfo queryById(Integer id) {
        UserInfo userInfo = userInfoMapper.selectById(id);
        return userInfo;
    }

    @Override
    public List<UserInfo> queryAll() {
        return userInfoMapper.selectList(null);
    }

    @Override
    public Page<UserInfo> getPage(int currentPage, int pageSize) {
        Page<UserInfo> page = new Page(currentPage, pageSize);
        userInfoMapper.selectPage(page, null);
        return page;
    }


    @Override
    public boolean delete(Integer id) {
        int i = userInfoMapper.deleteById(id);
        return i>0 ? true:false;
    }


}
